package fun.ipconfig.shopping.controller;

import fun.ipconfig.shopping.dao.PlatFormAdminDao;
import fun.ipconfig.shopping.entity.LeftBarEntity;
import fun.ipconfig.shopping.entity.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author gtl
 */
@RestController
@RequestMapping("/platform/admin")
public class PlatFormAdminController {
    Logger log = LoggerFactory.getLogger(PlatFormAdminController.class);
    PlatFormAdminDao platFormAdminDao;
    public PlatFormAdminController(PlatFormAdminDao platFormAdminDao){
        this.platFormAdminDao = platFormAdminDao;
    }

    @PostMapping("/add/left/bar")
    Result setLeftBar(@RequestParam("name") String name, @RequestParam("img") MultipartFile multipartFile) {
        try {
            LeftBarEntity leftBar = new LeftBarEntity();
            leftBar.setName(name);
            leftBar.setImg(multipartFile.getBytes());
            platFormAdminDao.saveLeftBar(leftBar);
        } catch (IOException e) {
            log.error(e.getMessage());
            return new Result().setStatus(500).setMsg("上传失败!");
        }
        return new Result().setStatus(200).setMsg("修改成");
    }
}